package com.abvnet.project.water.project.controller;

import com.abvnet.common.utils.poi.ExcelUtil;
import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectComment;
import com.abvnet.project.water.project.service.IProjectCommentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工互评信息操作处理
 * 
 * @author duj
 * @date 2019-07-19
 */
@Controller
@RequestMapping("/project/projectComment")
public class ProjectCommentController extends BaseController {
    private String prefix = "project/projectComment";
	
	@Autowired
	private IProjectCommentService projectCommentService;
	
	@RequiresPermissions("project:projectComment:list")
	@GetMapping()
	public String projectComment()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询员工互评列表
	 */
	@RequiresPermissions("project:projectComment:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProjectComment projectComment) {
		startPage();
        List<ProjectComment> list = projectCommentService.selectProjectCommentList(projectComment);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出员工互评列表
	 */
	@RequiresPermissions("project:projectComment:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectComment projectComment) {
    	List<ProjectComment> list = projectCommentService.selectProjectCommentList(projectComment);
        ExcelUtil<ProjectComment> util = new ExcelUtil<ProjectComment>(ProjectComment.class);
        return util.exportExcel(list, "projectComment");
    }
	
	/**
	 * 新增员工互评
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存员工互评
	 */
	@RequiresPermissions("project:projectComment:add")
	@Log(title = "员工互评", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProjectComment projectComment) {
		return toAjax(projectCommentService.insertProjectComment(projectComment));
	}

	/**
	 * 修改员工互评
	 */
	@GetMapping("/edit/{commentId}")
	public String edit(@PathVariable("commentId") Long commentId, ModelMap mmap) {
		ProjectComment projectComment = projectCommentService.selectProjectCommentById(commentId);
		mmap.put("projectComment", projectComment);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存员工互评
	 */
	@RequiresPermissions("project:projectComment:edit")
	@Log(title = "员工互评", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProjectComment projectComment) {
		return toAjax(projectCommentService.updateProjectComment(projectComment));
	}
	
	/**
	 * 删除员工互评
	 */
	@RequiresPermissions("project:projectComment:remove")
	@Log(title = "员工互评", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(projectCommentService.deleteProjectCommentByIds(ids));
	}
	
}
